package hlhj.fhp.checkpoint.module

import android.content.Context
import android.nfc.Tag
import com.example.mymvp.mvp.BaseModule
import com.lzy.okgo.model.Response
import hlhj.fhp.checkpoint.http.Apis
import hlhj.fhp.checkpoint.http.CustomAction
import hlhj.fhp.checkpoint.http.LoadingAction
import hlhj.fhp.checkpoint.javaBean.MyBaseBean
import java.io.File
/**
 * Created by Never Fear   on 2018\11\20 0020.
Never More....
 */
class UoLoadModule :BaseModule {
    var listener:UploadListener?=null
    fun upLoad(c:Context,file:File){
        Apis.upLoad(file)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<MyBaseBean>>(c){
                                override fun httpSuccess(t: Response<MyBaseBean>) {
                                    listener?.upResp(t.body(),0)
                                }

                                override fun onComplete() {
//                                    super.onComplete()
                                }
                            })
                }
    }
    fun upLoad(c:Context,file:File,tag:Int){
        Apis.upLoad(file)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<MyBaseBean>>(c){
                                override fun httpSuccess(t: Response<MyBaseBean>) {
                                    listener?.upResp(t.body(),tag)
                                }
                                override fun onComplete() {
//                                    super.onComplete()
                                }
                            })
                }
    }


    interface UploadListener{
        fun upResp(myBaseBean: MyBaseBean,tag:Int)
    }
}